<template>
  <div class="edit-activity">
    <h2>编辑活动</h2>
    <form @submit.prevent="updateActivity">
      <div>
        <label for="title">标题：</label>
        <input type="text" id="title" v-model="activity.title" required />
      </div>
      <div>
        <label for="description">描述：</label>
        <textarea id="description" v-model="activity.description" required></textarea>
      </div>
      <div>
        <label for="date">日期：</label>
        <input type="date" id="date" v-model="activity.date" required />
      </div>
      <div>
        <label for="location">地点：</label>
        <input type="text" id="location" v-model="activity.location" required />
      </div>
      <button type="submit">更新活动</button>
    </form>
  </div>
</template>

<script>
import activities from '../data/activities.js';

export default {
  data() {
    return {
      activity: {}
    };
  },
  created() {
    const id = parseInt(this.$route.params.id);
    this.activity = activities.find(a => a.id === id) || {};
  },
  methods: {
    updateActivity() {
      const index = activities.findIndex(a => a.id === this.activity.id);
      if (index !== -1) {
        activities[index] = this.activity;
      }
      this.$router.push('/activity-management');
    }
  }
};
</script>